package com.ruoyi.core.service.impl;

import java.util.Calendar;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.core.mapper.UserBannerMapper;
import com.ruoyi.core.domain.UserBanner;
import com.ruoyi.core.service.IUserBannerService;
import com.ruoyi.common.core.text.Convert;

/**
 * 轮播图列表Service业务层处理
 * 
 * @author lgc
 * @date 2020-08-17
 */
@Service
public class UserBannerServiceImpl implements IUserBannerService 
{
    @Autowired
    private UserBannerMapper userBannerMapper;

    /**
     * 查询轮播图列表
     * 
     * @param bannerId 轮播图列表ID
     * @return 轮播图列表
     */
    @Override
    public UserBanner selectUserBannerById(Long bannerId)
    {
        return userBannerMapper.selectUserBannerById(bannerId);
    }

    /**
     * 查询轮播图列表列表
     * 
     * @param userBanner 轮播图列表
     * @return 轮播图列表
     */
    @Override
    public List<UserBanner> selectUserBannerList(UserBanner userBanner)
    {
        userBanner.setCreatedBy(userBanner.getUserId());
        userBanner.setCreatedDate(Calendar.getInstance().getTime());
        return userBannerMapper.selectUserBannerList(userBanner);
    }

    /**
     * 新增轮播图列表
     * 
     * @param userBanner 轮播图列表
     * @return 结果
     */
    @Override
    public int insertUserBanner(UserBanner userBanner)
    {
        userBanner.setCreatedBy(userBanner.getUserId());
        userBanner.setCreatedDate(Calendar.getInstance().getTime());
        return userBannerMapper.insertUserBanner(userBanner);
    }

    /**
     * 修改轮播图列表
     * 
     * @param userBanner 轮播图列表
     * @return 结果
     */
    @Override
    public int updateUserBanner(UserBanner userBanner)
    {
        return userBannerMapper.updateUserBanner(userBanner);
    }

    /**
     * 删除轮播图列表对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteUserBannerByIds(String ids)
    {
        return userBannerMapper.deleteUserBannerByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除轮播图列表信息
     * 
     * @param bannerId 轮播图列表ID
     * @return 结果
     */
    @Override
    public int deleteUserBannerById(Long bannerId)
    {
        return userBannerMapper.deleteUserBannerById(bannerId);
    }

    @Override
    public Boolean checkBannerSequence(Long bannerSequence,Long userId) {
        Boolean result = false;
        Integer count = userBannerMapper.selectCount(bannerSequence,userId);
        if(count.equals(0)){
            result = true;
        }
        return result;
    }

    @Override
    public List<UserBanner> selectUserBanner(Long userId) {
        List<UserBanner> list =  userBannerMapper.selectAll(userId);
        return list;
    }
}
